﻿using System;
using com.Bliss.Infrastructure;
namespace com.Bliss.Services
{
    public class PostService : IPostService
    {
        public TypedCollectionResponse<Bliss.Post> GetPosts(int companyId)
        {
            var post = new Domain.Post.Wall();
            try
            {
                var allScraps = post.GetPosts(companyId);
                return new TypedCollectionResponse<Bliss.Post>(allScraps);
            }
            catch (Exception ex)
            {
                var data = new TypedCollectionResponse<Bliss.Post>(null);
                data.HasErrors = true;
                data.errors = new string[] { ex.Message };
                return data;
            }
        }
        public TypedCollectionResponse<Bliss.Post> GetPrivatePosts(int userId)
        {
            var post = new Domain.Post.Wall();
            try
            {
                var allScraps = post.GetPrivatePosts(userId);
                return new TypedCollectionResponse<Bliss.Post>(allScraps);
            }
            catch (Exception ex)
            {
                var data = new TypedCollectionResponse<Bliss.Post>(null);
                data.HasErrors = true;
                data.errors = new string[] { ex.Message };
                return data;
            }
        }
        public TypedCollectionResponse<Bliss.Post> GetChildPosts(int parentID)
        {
            var post = new Domain.Post.Wall();
            try
            {
                var allScraps = post.GetChildPosts(parentID);
                return new TypedCollectionResponse<Bliss.Post>(allScraps);
            }
            catch (Exception ex)
            {
                var data = new TypedCollectionResponse<Bliss.Post>(null);
                data.HasErrors = true;
                data.errors = new string[] { ex.Message };
                return data;
            }
        }
        public void SendPrivateMessage(int fromUserID, int? parentPostID, int? toUserID, string Message)
        {
            if (Message.Trim().Equals(string.Empty))
                return;
            var post = new Domain.Post.Wall();
            try
            {
                post.SendPrivateMessage(fromUserID, parentPostID, toUserID, Message);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public void Post(int fromUserID, int? toPostID, string Message)
        {
            if (Message.Trim().Equals(string.Empty))
                return;
            var post = new Domain.Post.Wall();
            try
            {
                post.Post(fromUserID, toPostID, Message);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public void DeletePost(int postID)
        {
            var post = new Domain.Post.Wall();
            try
            {
                post.DeletePost(postID);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
    }
}
